<meta charset="UTF-8">
<?php
$id = 0;
$guest = false;

if (isset($_GET['uid']) && $_GET['uid'] != $_SESSION['id']) {
    $id = $_GET['uid'];
    $guest = true;
} else {
    $id = $_SESSION['id'];
    $guest = false;
}

?>

<script>
    function submitDelete() {
        $('#action').val('delete');
        $('#imgform').submit();
    }

    function submitChange() {
        $('#action').val('change');
        $('#imgform').submit();
    }

</script>


<div id="profileimgdiv">
    <div class="sectionheader">
        Изображение пользователя:
    </div>
    <div class="fakeimage">
        <img src="user_img/<?= getAvatarSrc($id) ?>" id="profileimg">
    </div>
    <?php
    if (!$guest) {
        ?>
        <form enctype="multipart/form-data" method="post" action="profile/handler_img.php" id="imgform">

            <input type="hidden" name="MAX_FILE_SIZE" value="25000000"/>

            <div style="display: inline-block; width: 100%">
                <div id="fileinputdiv">
                    <input name="image" onchange="submitChange()" type="file" accept=".jpg, .png, .jpeg, .gif"
                           id="realfileinput">

                    <div id="fileinput">Новое</div>

                </div>
                <div class="profileimgbutton" onclick="submitDelete()">
                    Удалить
                </div>
            </div>

            <input type="hidden" name="action" id="action">
        </form>
    <?php
    }
    ?>

</div>